﻿using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Practices.Composite.Presentation.Commands;

namespace Core.Infrastructure.CommandExtensions
{
    public class TextAreaKeyEnterCommandBehavior : CommandBehaviorBase<TextBox>
    {
        public TextAreaKeyEnterCommandBehavior(TextBox targetObject) : base(targetObject)
        {
            targetObject.KeyDown += new KeyEventHandler(TargetObjectKeyDown);
        }

        void TargetObjectKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter) return;
            base.CommandParameter = ((TextBox) sender).Text;
            base.ExecuteCommand();
        }
    }
}
